import React ,{useEffect, useState} from 'react';
import { Button, Table } from 'antd'
import '../../styles/chen/systemnotice.scss'
import TimeList from "../../components/chen/TimeList";
import * as service from '../../api/chen/index'
import { useNavigate } from 'react-router-dom';
interface Props{

}
function SystemNotice(props: Props) {
  var navigate=useNavigate()
  const [data, setData] = useState([])
  useEffect(() => {
    service.notice_list().then(res => {
      setData(res.data)
    })
  },[])
    // const data = [
    //     {
    //      id: '1',
    //         newstitle: '服务包停用通知',
    //         newscontent:"编号0009090服务包因服务项目更新将于10/09-10/11号暂停使用，预计10/12日重新恢复使用，敬请期待",
    //         person: "李明明",
    //         condition: '待发布',
    //       endingtime: 'New York No. 1 Lake Park',
        
    //     description:''
    //     },
    //     {
    //      id: '2',
    //         newstitle: '服务包停用通知',
    //         newscontent:"编号0009090服务包因服务项目更新将于10/09-10/11号暂停使用，预计10/12日重新恢复使用，敬请期待",
    //         person: "李明明",
    //         condition: '待发布',
    //       endingtime: 'New York No. 1 Lake Park',
        
    //     description:''
    //     },
    //     {
    //      id: '3',
    //         newstitle: '服务包停用通知',
    //         newscontent:"编号0009090服务包因服务项目更新将于10/09-10/11号暂停使用，预计10/12日重新恢复使用，敬请期待",
    //         person: "李明明",
    //         condition: '待发布',
    //         endingtime: 'New York No. 1 Lake Park',
    //         description:''
    //     },
        
    //   ];
    const myDelete = (row:any) => {
      service.notice_delete({ id: row.index}).then((res) => {
        console.log(res)
      })
      setTimeout(() => {
        navigate(0)
    }, 1000)
    }
    const columns= [
    
        {
          title: '消息标题',
          dataIndex: 'newstitle',
        },
        {
          title: '消息内容',
          dataIndex: 'newscontent',
        },
        {
          title: '发布人',
          dataIndex: 'person',
        },
        {
          title: '状态',
          dataIndex: 'condition',
        },
        {
          title: '操作时间',
          dataIndex: 'endingtime',
        },
        {
            title: '操作',
              render: (_: any, row: any) => {
                  return (
                      <>
                   <span style={{marginRight:10,color:'blue'}} >编辑</span>
                      <span style={{ color: 'red' }} onClick={() => { myDelete(row) }}>删除</span>
                  </>
               )
           }
          },
    ];
    
       
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
    
    
    const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
        console.log('selectedRowKeys changed: ', newSelectedRowKeys);
        setSelectedRowKeys(newSelectedRowKeys);
      };
    
      const rowSelection = {
        selectedRowKeys,
        onChange: onSelectChange,
      };
    return (
        <div className='system-notice'>
            系统公告
            <div className='notice-header'>
                <TimeList></TimeList>
                <div>
                    <Button type="primary" className='btn'>新增系统公告</Button>
                    <Button>导出</Button>
                </div>
                </div>
            <Table rowSelection={rowSelection} columns={columns} dataSource={data} />
        </div>
    );
}

export default SystemNotice;